﻿using UnityEngine;
using System.Collections;

public class InGameButtonClick : MonoBehaviour {

	public bool pauseButton;
	public bool quitToMainMenu;
	public bool resumeButton;
	public bool restartButton;
    public bool adButton;
    public TextMesh score;
    public GameObject pauseMenuHUD;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		//Debug.Log (pauseButton);
	}


	void OnMouseDown()
	{	
		Debug.Log ("aaa");
		ButtonAction();		
	}


	void ButtonAction()
	{
		//if pauseButton is pressed, pause the game 
		if (pauseButton){ 
			CharacterController.canMove = false; 
			pauseMenuHUD.SetActive(true);		
		}
		if (resumeButton){ 
			CharacterController.canMove = true; 
			pauseMenuHUD.SetActive(false);	

		}
		if (restartButton){ 
			//CharacterController.canMove = true; 
			Application.LoadLevel(Application.loadedLevelName);		
		}
		if (quitToMainMenu){ 
			CharacterController.canMove = true; 
			Application.LoadLevel("MenuScene");		
		}
        if (adButton)
        {
			TouchWatchAds();
        }


    }

    public void TouchWatchAds()
    {
        string videoAdid = VideData.Instance.GetVide();
        TTSDK.TTRewardedVideoAd r = AdMgr.Instance.ShowVideoAdNew(videoAdid);
        Time.timeScale = 0.0f;
        //创建激励视频关闭回调
        r.OnClose += (bol, val) =>
        {
            Debug.Log("关闭广告 ，是否已经看完" + bol);
            //看完广告获得提示
            if (bol)
            {
                HelperScript.score += 1000;
                score.text = "分数: " + HelperScript.score;
                MaidianNew.MaidianBackCallback(" ");
                Debug.Log("广告看完");
                Time.timeScale = 1.0f;
            }
            else
            {
                Debug.Log("广告未看完");
                Time.timeScale = 1.0f;
            }
        };

        //创建报错回调  
        r.OnError += (code, errorMessage) =>
        {
            Time.timeScale = 1.0f;
            Debug.Log("code:" + code + "错误信息：" + errorMessage);
        };

        //展示广告（新版本必须调用，不然无法展示出来广告）
        r.Show();

    }

}
